package com.bei_en.common.spring;

import java.beans.PropertyEditorSupport;
import org.springframework.util.StringUtils;
import com.bei_en.common.util.DateUtil;

public class DateEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String text) throws IllegalArgumentException {

		if (!StringUtils.hasText(text)) {
			setValue(null);
		} else {
			setValue(DateUtil.parseDate(text));
		}
	}

	@Override
	public String getAsText() {

		return getValue().toString();
	}
}
